package com.edu.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class userLogOutServlet
 */
@WebServlet(name = "userLogOut", description = "userLogOut", urlPatterns = { "/userLogOut" })
public class userLogOutServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		session.removeAttribute("logInUser");
		Cookie deleteCookie1 = new Cookie("username", "");
		deleteCookie1.setMaxAge(0);
		deleteCookie1.setPath("/");
		response.addCookie(deleteCookie1);
		Cookie deleteCookie2 = new Cookie("password", "");
		deleteCookie2.setMaxAge(0);
		deleteCookie2.setPath("/");
		response.addCookie(deleteCookie2);
		response.sendRedirect("index.jsp");
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
